import platform
import pkg_resources
import os
import stat

def get_bin(bin_name):
    sys_type = platform.system().lower()
    machine_type = platform.machine().lower()
    dir_name = sys_type + '-' + machine_type
    bin_file = os.path.join('./bin', dir_name, bin_name)
    if sys_type == 'windows':
        bin_file += '.exe'
    bin_file = pkg_resources.resource_filename(__name__, bin_file)

    if not os.path.exists(bin_file):
        raise FileNotFoundError(bin_file)
    
    if sys_type == 'linux':
        os.chmod(bin_file, 0o755)
    
    return bin_file